define(function(require){

	
	var loadingUtils = require("app/utils/LoadingUtils");
	
	var c = require('app/utils/CommonUtils');
	var hc = require('app/utils/HttpClientUtils');
	var dbu = require('app/utils/DBUtils');
	
	var wx = api.require('wx');
	return {
		share: function(share_type, title,roomuuid, calback_func){
		
			var scene = "";
			if(share_type == 1){ // 微信好友
				scene = "session";
			}else if(share_type == 2) { // 朋友圈 
				scene = "timeline";
			}else {
				return;
			}
//			http://app.haojs.com.cn/approom/b8dd2e28-b8de-4e5e-8f8b-678fd6c7d390
			var contentUrl = "http://app.haojs.com.cn/approom/"+roomuuid;//"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf75a72e56bd8726d&redirect_uri=http://www.haojs.com.cn/form/api/wm/route&response_type=code&scope=snsapi_base&state=/wm/room/80fea9a8-5db7-48c4-bd3c-2b9e0d58eaf8/attend#wechat_redirect";
			var thumb = "widget://res/logo.png";
			var des = "好教授在线邀请您加入！让知识分享更生动！";
			
			wx.shareWebpage({
	    	    scene: scene,
	    	    title: title,
	    	    description: des,
	    	    thumb: thumb,
	    	    contentUrl: contentUrl
	    	}, function(ret, err){
	    		calback_func();	    	    
	    	});
		},

		login:function(callback_func){
			
			loadingUtils.openloading("数据加载","稍后片刻");
			
			wx.isInstalled(function(ret, err) {
			
				if (ret.installed) { // 已安装微信
					wx.auth(function(ret, err){
						
						if(!ret.status){
							alert("您未进行登陆授权");
							loadingUtils.closeloading();
							callback_func(false);
							return;
						}
						
						wx.getToken({ // 获取accesstoken
							code: ret.code
						},function(ret,err){
							if(!ret.status){
								alert("您未进行登陆授权");
								loadingUtils.closeloading();
								callback_func(false);
								return;
							}
							var accesstoken = ret.accessToken;
							wx.getUserInfo({// 获取微信用户信息
								accessToken : ret.accessToken,
							 	openId : ret.openId
							}, function(ret,err){
								
								loadingUtils.closeloading();
								
								if(!ret.status){
									alert("未获得用户授权");
									callback_func(false);	
									
									return;
								}
								callback_func(true, ret, accesstoken);	
								
							});						
							
						});							
					});
								
				}else{ // 未安装微信
					alert("您未安装微信");
					loadingUtils.closeloading();
					callback_func(false);
					return;
				}
			});
		}
		
	};
});